package com.jyw.business.ast.domain.dto.web;

import com.jyw.business.ast.domain.AstConsumableRecord;
import com.jyw.common.utils.DateUtils;
import com.jyw.common.utils.SecurityUtils;
import com.jyw.system.domain.vo.SimpleFileVo;
import com.jyw.system.utils.FileUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.List;
import java.util.stream.Collectors;

@Data
@ApiModel("耗材库存-请求实体")
public class AstConsumableReverseDto {

    @ApiModelProperty("备注")
    private String remark;

    @ApiModelProperty("附件")
    private List<SimpleFileVo> enclosure;

    @ApiModelProperty("耗材列表")
    private List<ReserveDto> reverseList;

    public List<AstConsumableRecord> buildRecord(String type){
        String enclosureId = FileUtils.fileToId(enclosure);
        return getReverseList().stream().map(data -> {
            AstConsumableRecord record = new AstConsumableRecord();
            record.setType(type);
            record.setConsumableId(data.getId());
            record.setQuantity(data.getQuantity());
            record.setRemark(getRemark());
            record.setEnclosureId(enclosureId);
            record.setCreateUser(SecurityUtils.getUserId());
            record.setCreateTime(DateUtils.getNowDate());
            return record;
        }).collect(Collectors.toList());
    }
}
